package com.zjy.service.role;

import com.zjy.dao.BaseDao;
import com.zjy.dao.role.RoleDao;
import com.zjy.dao.role.RoleDaoImpl;
import com.zjy.pojo.Role;
import com.zjy.pojo.User;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class RoleServiceImpl implements RoleService{
    //引入Dao  记住用构造器
    private RoleDao roleDao;
    public RoleServiceImpl() {
        roleDao = new RoleDaoImpl();
    }

    //获取角色列表（根据角色查询时下拉框要用）
    public List<Role> getRoleList(){
        Connection connection=null;
        List<Role> roleList=null;
        try {
            connection= BaseDao.getConnection();
            roleList=roleDao.getRoleList(connection);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            BaseDao.closeResource(connection,null,null);
        }
        return  roleList;
    }

    @Test
    public void Test(){
        RoleServiceImpl roleService = new RoleServiceImpl();
        List<Role> roleList = roleService.getRoleList();
        //System.out.println(roleList.toArray().toString());
        for (Role role : roleList) {
            System.out.println(role.getRoleName());
        }

    }
}
